<script type="text/javascript" src="<?php echo URL::base(); ?>media/js/jquery.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css"
      media="all"/>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.form.3.51.0.js"></script>
<script src="<?php echo URL::base() ?>media/layer/layer.js"></script>
<style>
    .times {display:block;margin:15px 0;}/*首先，我们要创建一个容器class*/
    .times ul {margin-left:25px;border-left:2px solid #ddd;list-style: none;}/*利用ul标签的特性，设置外边框左移25px，左边边框是2px粗的实心线，颜色一般要浅一点*/
    .times ul li {width:100%;margin-left:-12px;line-height:20px;font-weight:narmal;}/*一般情况，通过li标签控制圆点回到时间线上，然后控制要出现的文字大小和是否粗体*/
    .times ul li b {width:8px;height:8px;background:#fff;border:2px solid #555;margin:5px;border-radius:6px;-webkit-border-radius:6px;-moz-border-radius:6px;overflow:hidden;display:inline-block;float:left;}/*利用处理加粗以外没有其它特别属性b标签做时间轴的圆点。*/
    .times ul li span {padding-left:7px;font-size:12px;line-height:20px;color:#999;}/*设置span标签的属性，让它来做时间显示，加一点边距，使时间显示离时间线远一点*/
    .times ul li:hover b {border:2px solid #3AB056;;}/*注意这一行，前面的li标签后面加了一个:hover伪属性，意思是鼠标移上来，激活后面的属性，这样可以设置鼠标移动到整个时间范围的时候，时间点和时间显示会变色*/
    .times ul li:hover span {color:#3AB056;;}/*同上*/
    .times ul li p {padding-left:30px;font-size:14px;line-height:25px;}/*这里利用段落标签p做文字介绍*/

</style>
<script type="text/javascript">
    $(document).ready(function () {
        $("#transportation_expense").dblclick(function () {
            var id = $(this).next().text();
            var dialog = art.dialog({title: '修改运费', lock: true});
            dialog.content('<p>数据查询中,请稍后...<p>');
            $.get("<?php echo URL::base(TRUE)?>purchases/selectpurchase/change_transportation_expense",
                {"id": id},
                function (view) {
                    dialog.content(view);
                });
        });
    });
</script>

<h4>供应商信息</h4>
<table class="table table1" id="purchase_order">
    <thead>
    <tr>
        <th>供应商名称</th>
        <th>地址</th>
        <th>电话</th>
        <th>传真</th>
        <th>联系人</th>
        <th>手机</th>
        <th>备注</th>
        <th>户名</th>
        <th>开户行</th>
        <th>账号</th>
    </tr>
    </thead>
    <?php if (isset($supplier) && !empty($supplier)) { ?>
        <tr>
            <td>
                <?php echo $supplier['vProviderName']; ?>
            </td>
            <td>
                <?php echo isset($supplier['vAddress'])?$supplier['vAddress']:''; ?>
            </td>
            <td>
                <?php echo $supplier['vPhone']; ?>
            </td>
            <td>
                <?php echo $supplier['vFax']; ?>
            </td>
            <td>
                <?php echo $supplier['vContact']; ?>
            </td>
            <td>
                <?php echo $supplier['vMobile']; ?>
            </td>
            <td width="100">
                <?php echo isset($purchase_order['remark'])?$purchase_order['remark']:'' ?>
            </td>
            <td>
                <?php echo $supplier['vAccountname']; ?>
            </td>
            <td>
                <?php echo $supplier['vEstablishBank']; ?>
            </td>
            <td>
                <?php echo $supplier['vAccount']; ?>
            </td>
        </tr>
    <?php } ?>
</table>
</br>
<h4>产品信息</h4>
<table class="table table1" id="info_product">
    <thead>
    <tr>
        <th>SKU</th>
        <th>中文名称</th>
        <th>报关品名</th>
        <th>预约单价</th>
        <th>含税单价</th>
        <th>退税单价</th>
        <th>采购数量</th>
        <th>单位</th>
        <th>储位</th>
        <th>加点税率</th>
        <th>退税率</th>
        <th>税额</th>
        <th>采购未税金额</th>
        <th>采购已税金额</th>
    </tr>
    </thead>
    <tbody>
    <?php if (isset($product_info) && !empty($product_info)) { ?>
        <?php foreach ($product_info as $p_in) { ?>
            <tr>
                <td style="word-break: break-all;"><?php echo $p_in['sku'] ?></td>
                <td style="word-break: break-all;"><?php echo $p_in['sku_name'] ?></td>
                <td><?php echo $p_in['item'] ?></td>
                <td><?php echo sprintf("%.3f", $p_in['single_price']) ?></td>
                <td id="tax_price_<?php echo $p_in['id'] ?>"><?php echo sprintf("%.3f", $p_in['single_price'] * (1 + $p_in['real_tax_rate'])) ?></td>
                <td id="no_tax_price_<?php echo $p_in['id'] ?>"><?php echo sprintf("%.3f", $p_in['single_price'] * (1 + $p_in['real_tax_rate']) / (1 + $p_in['rebate'])) ?></td>
                <td><?php echo $p_in['quantity'] ?></td>
                <td><?php echo $p_in['sku_unit'] ?></td>
                <td><?php echo $p_in['products_newplace'] ?></td>
                <td width="130" class="real_tax_rate">
                    <form action="<?php echo URL::base() ?>purchases/selectpurchase/saveTaxRate" method="post"
                          onsubmit="return checkDetailSubmit(<?php echo $p_in['id'] ?>,<?php echo $p_in['rebate'] ?>)">
                        <input type="text" id="name_<?php echo $p_in['id'] ?>"
                               value="<?php echo $p_in['real_tax_rate'] ?>" class="input-mini"
                               onkeyup="clearNoNum(this)" name="real_tax_rate"
                               onblur="sumMoney(this.value,<?php echo $p_in['single_price'] ?>,<?php echo $p_in['rebate'] ?>,<?php echo $p_in['quantity'] ?>,<?php echo $p_in['id'] ?>)">
                        <input type="hidden" name="id" value="<?php echo $p_in['id'] ?>">
                        <input type="hidden" name="p_id" value="<?php echo $_GET['p_id'] ?>">
                        <button type="submit" class="btn btn-xs">保存</button>
                    </form>
                </td>
                <td> <?php echo strval(round($p_in['rebate'], 2) * 100)."%" ?></td>
                <td>17%</td>
                <td><?php echo sprintf("%.3f", $p_in['money']) ?></td>
                <td id="money_<?php echo $p_in['id'] ?>"><?php echo sprintf("%.3f", $p_in['single_price'] * (1 + $p_in['real_tax_rate']) * $p_in['quantity']) ?></td>
            </tr>
        <?php }
    } ?>
    </tbody>
</table>

<ul id="myTab" class="nav nav-tabs">
    <li class="active">
        <a href="#goods" data-toggle="tab">收货明细</a>
    </li>
    <li><a href="#quality" data-toggle="tab">质检明细</a></li>
    <li><a href="#putin" data-toggle="tab">入库明细</a></li>
    <li><a href="#info" data-toggle="tab">日志信息</a></li>

</ul>
<div id="myTabContent" class="tab-content">
    <div class="tab-pane fade in active" id="goods">
        <table class="table table1">
            <thead>
            <tr>
                <th>收货单号</th>
                <th>收货明细单号</th>
                <th>收货人</th>
                <th>SKU</th>
                <th>收货量</th>
                <th>收货时间</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($gets as $c => $v) { ?>
                <tr>
                    <td><?php echo $v['getid'] ?></td>
                    <td><?php echo $v['getdetailid'] ?></td>
                    <td><?php echo $v['getman'] ?></td>
                    <td><?php echo $v['sku'] ?></td>
                    <td><?php echo $v['arrival_quantity'] ?></td>
                    <td><?php echo $v['gettime'] ?></td>
                </tr>
            <?php } ?>
            </tbody>
        </table>
    </div>
    <div class="tab-pane fade" id="quality">
        <table class="table table1">
            <thead>
            <tr>
                <th>质检明细单号</th>
                <th>质检人</th>
                <th>质检量</th>
                <th>合格量</th>
                <th>不合格量</th>
                <th>质检时间</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($checks as $ch => $ck) { ?>
                <tr>
                    <td><?php echo $ck['recieve_detail_id'] ?></td>
                    <td><?php echo $ck['check_man'] ?></td>
                    <td><?php echo $ck['check_quantity'] ?></td>
                    <td><?php echo $ck['qualified_quantity'] ?></td>
                    <td><?php echo $ck['unquality_count'] ?></td>
                    <td><?php echo $ck['invoice_date'] ?></td>
                </tr>
            <?php } ?>
            </tbody>
        </table>
    </div>
    <div class="tab-pane fade" id="putin">
        <table class="table table1">
            <thead>
            <tr>
                <th>入库单号</th>
                <th>入库人</th>
                <th>入库时间</th>
                <th>SKU</th>
                <th>入库量</th>
                <th>单价</th>
                <th>金额</th>
                <th>运费</th>
                <th>成本</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($ins as $in => $s) { ?>
                <tr>
                    <td><?php echo $s['inid'] ?></td>
                    <td><?php echo $s['inman'] ?></td>
                    <td><?php echo $s['intime'] ?></td>
                    <td><?php echo $s['sku'] ?></td>
                    <td><?php echo $s['inquantity'] ?></td>
                    <td><?php echo $s['single_price'] ?></td>
                    <td><?php echo $s['money'] ?></td>
                    <td><?php echo $s['transportation_expense'] ?></td>
                    <td><?php echo $s['cost'] ?></td>
                </tr>
            <?php } ?>
            </tbody>
        </table>
    </div>

    <div class="tab-pane fade" id="info">
        <div class="times">
            <ul>
                <?php foreach ($logs as $k=>$v){?>
                    <li><b></b><span><?php echo $v['create_time']; ?></span><p><?php echo $v['username'].' : '.$v['result_info']; ?></p></li>
                <?php }?>

            </ul>
        </div>

        </div>


</div>

<button type="button" class="btn btn-info"
        onclick="location.href='<?php echo URL::site() ?>purchases/select/purchaseindex'">返回
</button>


<script>
    //计算含税金额
    function sumMoney(real_tax_rate, price, rebate, qty, id) {
        var money = (1 + Number(real_tax_rate)) * price * qty;
        var tax_price = (1 + Number(real_tax_rate)) * price;
        var no_tax_price = tax_price / (1 + Number(rebate));
        $('#money_' + id).text(money.toFixed(3));
        $('#tax_price_' + id).text(tax_price.toFixed(3));
        $('#no_tax_price_' + id).text(no_tax_price.toFixed(3));
    }
    //取消采购单
    function delete_purchase(p_detail_id) {
        $.post(
            "<?php echo URL::site(); ?>purchase/deletepurchase",
            {p_detail_id: p_detail_id},
            function (re) {
                //alert(re);return ;
                if (re == '"cancel success"') {
                    layer.alert('取消或者终结成功', {icon: 5});
                }
                else {
                    layer.alert('状态不适合取消或终结', {icon: 5});
                }
            });
    }
    //单条采购单录入
    function uploadpay(purchaseorder_id) {
        if (!purchaseorder_id) {
            layer.alert('没有正确的订单号', {icon: 5});
            return;
        }
        $.get("<?php echo URL::base() ?>uploadpay/payshow",
            {purchaseorder_id: purchaseorder_id},
            function (data) {
                if (data == 0) {
                    layer.alert('该采购单不存在', {icon: 5});
                    return;
                }
                if (data == 1) {
                    layer.alert('该采购单状态不为已打印', {icon: 5});
                    return;
                }
                var obj = jQuery.parseJSON(data);
                art.dialog({
                    title: '单条采购付款单录入',
                    lock: true,
                    opacity: 0.3,	// 透明度
                    content: obj.view,
                    button: [{
                        name: '关闭',
                        callback: function () {
                            window.location.reload();

                        }
                    }]
                });
            });
    }
    $("#gets").click(function () {
        if ($("#hehe1").hasClass("display_div")) {
            $("#hehe1").removeClass('display_div');
        } else {
            $("#hehe1").addClass('display_div');
        }
    });
    $("#checks").click(function () {
        if ($("#hehe2").hasClass("display_div")) {
            $("#hehe2").removeClass('display_div');
        } else {
            $("#hehe2").addClass('display_div');
        }
    });
    $("#ins").click(function () {
        if ($("#hehe3").hasClass("display_div")) {
            $("#hehe3").removeClass('display_div');
        } else {
            $("#hehe3").addClass('display_div');
        }
    });
    //单机按钮展示
    function show(id) {
        if ($(id).hasClass("display_div")) {
            $("#add_more").removeClass('display_div');
        } else {
            $("#add_more").addClass('display_div');
        }
    }
    function clearNoNum(obj) {
        obj.value = obj.value.replace(/[^\d.]/g, "");  //清除“数字”和“.”以外的字符

        obj.value = obj.value.replace(/^[\.1-9]/g, "");  //验证第一个字符是数字而不是.

        obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.

        obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d\d).*$/, '$1$2.$3'); //只能输入三个小数
    }
    function checkDetailSubmit(id, rebate) {
        var str = $('#name_' + id).val(),
            dt = /0\.\d(\d\d)/
        if ($.trim(str) == '') {
            layer.alert('加点税率不能为空', {icon: 5});
            return false;
        }
        if (str > rebate) {
            layer.alert('加点税率不能大于退税率', {icon: 5});
            return false;
        }
        if (dt.test(str) == false) {
            layer.alert('加点税率输入有误', {icon: 5});
            return false;
        }
        return true;
    }
</script>
